package com.six.backend.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.six.backend.pojo.ResultMessage;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: skyler
 * @Date: 2021/11/14 20:47
 * @Description: 用来封装消息的工具类
 */
public class MessageUtils {

    public static  String getMessage(boolean isInform,boolean isPushMessage,boolean isShowOnlinePeople,String fromName,Integer toolId,Integer questionnaireId,Object message) {

        try {
            ResultMessage result = new ResultMessage();
            result.setPush(isPushMessage);
            result.setMessage(message);
            if (fromName != null) {
                result.setFromName(fromName);
            }
            if (toolId != null) {
                result.setToolId(toolId);
            }
            if (questionnaireId != null) {
                result.setQuestionnaireId(questionnaireId);
            }
            result.setInform(isInform);
            result.setShowOnlinePeople(isShowOnlinePeople);
            result.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(result);
        }catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
